/*
	Copyright (C) 2008 by Jean-François Geyelin
	jfgeyelin@gmail.com

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the
	Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/




#include "globals.h"
#include "all.h"
#include "DisplayString.h"
#include "drawButtonInMenu.h"

void initColorsGlobals(void) {

    transparentColor = SDL_MapRGB( screenSurface->format, 255, 0, 255 );



    buttonsColor = SDL_MapRGB( screenSurface->format, 255, 255, 170 );
    buttonsBorderColor = SDL_MapRGB( screenSurface->format, 249, 249, 0 );
    buttonsHighColor = SDL_MapRGB( screenSurface->format, 255, 255, 81 );
    buttonsBorderHighColor = SDL_MapRGB( screenSurface->format, 249, 249, 0 );


    buttonsColor2 = SDL_MapRGB( screenSurface->format, 255, 244, 244 );
    buttonsBorderColor2 = SDL_MapRGB( screenSurface->format, 255, 183, 183 );
    buttonsHighColor2 = SDL_MapRGB( screenSurface->format, 255,213,213 );
    buttonsBorderHighColor2 = SDL_MapRGB( screenSurface->format, 255, 183, 183 );

    buttonsInactiveColor = SDL_MapRGB( screenSurface->format, 255, 255, 235 );
    buttonsInactiveBorderColor = SDL_MapRGB( screenSurface->format, 255, 255, 190 );



}


void drawButtonInMenu(SDL_Rect r, std::string str, SDL_Surface *destinationSurface, Uint32 backgroundColor, Uint32 borderColor) {
    SDL_FillRect(destinationSurface, &r, borderColor);
    r.x++;
    r.y++;
    r.w-=2;
    r.h-=2;
    SDL_FillRect(destinationSurface, &r, backgroundColor);
    int x = r.x + (r.w - (str.length()*FONT_SPACING))/2;
    int y = r.y + (r.h - 16)/2;
    DisplayString::drawString3(str.c_str(), x, y, destinationSurface);
}


int drawButtonInMenu(int mouseX, int mouseY, SDL_Rect r, std::string str, SDL_Surface *destinationSurface, int type) {
    if (mouseX >= r.x && mouseX < r.x + r.w && mouseY >= r.y && mouseY < r.y + r.h) {
        if (type==0)
        drawButtonInMenu(r, str,destinationSurface, buttonsHighColor, buttonsBorderHighColor);
        else
        drawButtonInMenu(r, str,destinationSurface, buttonsHighColor2, buttonsBorderHighColor2);
        return 1;
    }
    else
    {
        if (type==0)
        drawButtonInMenu(r, str,destinationSurface, buttonsColor, buttonsBorderColor);
        else
        drawButtonInMenu(r, str,destinationSurface, buttonsColor2, buttonsBorderColor2);
        return 0;
    }
}


int drawButtonInMenu(int mouseX, int mouseY, int x, int y, int w, int h, std::string str, SDL_Surface *destinationSurface, int type, int returnValue) {
    SDL_Rect r;
    r.x = x;
    r.y = y;
    r.w = w;
    r.h = h;
    if (drawButtonInMenu(mouseX, mouseY, r, str, destinationSurface, type))
    return returnValue;
    return 0;
}





